
(function($) {
	
	$.survey = function(surveyLink, cookieName, options) {
		opts = $.extend({}, $.survey.defaults, options);
		//if cookie is not set

		if ($.cookie(cookieName) == null) {	
			//show dialog
			var popupProbability = opts.popupProbability;

			if (Math.random() >= (popupProbability*5)) return;
			
			//set cookie 
			$.cookie(cookieName, 'now_set', { expires: 30 });
		
			$.survey.createModal(opts.title, surveyLink, opts.width, opts.height);
		}
	}

	$.survey.createModal = function(title, url, w, h) {
		url = url + "?TB_iframe=true&amp;height=" + h + "&amp;width=" + w;
		tb_show(title, url, null);		
	}


	$.survey.defaults = {
		width: 				'400', 				//width of popup box
		height: 			'400', 				//height of popup box
		popupProbability: 	1, 				//probability that popup box will appear to user
		title: 				'Take our survey'  //title of survey
	};
	
})(jQuery); 